﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.ADs;
using VK.Comm;
using VK.Casemeet.Employees;

namespace VK.Casemeet.Web.Admin.ADs
{
    public partial class ADAdd : System.Web.UI.Page
    {
        public string imgUrl = "null.jpg";

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="广告",Url="/Admin/ADs/ADList.aspx"},
                new MapPath{ Text="新建广告",Url="#"}
            };

            if (!IsPostBack)
            {
                ADHelper.BindTargetRAD(radTarget);
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            ADEntity AD = LoadEntity();

            if (ADBLL.InsertAD(AD) > 0)
            {
                Message.Msg(this.Page, CS.MsgAddSuccess, MessageType.Success);
                Util.ClearControl((this.Master as Site).contentBody.Controls);
                txtHits.Text = "0";
            }
            else
            {
                Message.Msg(this.Page, CS.MsgAddFailure, MessageType.Failure);
            }
        }

        protected ADEntity LoadEntity()
        {
            ADEntity ad = new ADEntity();
            ad.Code = txtCode.Text;
            ad.Target = int.Parse(radTarget.SelectedValue);
            ad.Description = txtDescription.Text.Trim();
            ad.Width = int.Parse(txtWidth.Text);
            ad.Height = int.Parse(txtHeight.Text);
            ad.Url = txtUrl.Text;
            ad.IsEnable = chkIsEnable.Checked;
            ad.Image = Util.GetFormString("hidImgUrl");
            ad.ProvinceID = EmployeeService.GetSessionEmployee().ProvinceID;
            ad.CityID = EmployeeService.GetSessionEmployee().CityID;

            return ad;
        }
    }
}